package com.jiangyg.mall.order.controller;

import com.jiangyg.mall.core.support.restful.Pagination;
import com.jiangyg.mall.core.support.restful.Result;
import com.jiangyg.mall.order.dto.OrderOperateHistoryDTO;
import com.jiangyg.mall.order.service.OrderOperateHistoryService;
import com.jiangyg.mall.order.vo.OrderOperateHistoryVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 类描述：订单操作历史记录控制器
 *
 * @author jiangyg
 * @version email@jiangyg.com
 * @date 2021-10-30 07:36:29
 */
@RestController
@RequestMapping("/order/orderOperateHistory")
public class OrderOperateHistoryController {

    /**
     * 订单操作历史记录接口
     */
    private final OrderOperateHistoryService orderOperateHistoryService;

    @Autowired
    public OrderOperateHistoryController(OrderOperateHistoryService orderOperateHistoryService) {
        this.orderOperateHistoryService = orderOperateHistoryService;
    }

    /**
     * 功能描述：订单操作历史记录分页查询
     *
     * @param request    请求
     * @param pagination 分页参数
     * @return 返回分页订单操作历史记录
     */
    @ResponseBody
    @PostMapping("/select")
    public Result<Pagination<OrderOperateHistoryVO>> select(HttpServletRequest request, @RequestBody Pagination<OrderOperateHistoryVO> pagination) throws Exception {
        return Result.ok(orderOperateHistoryService.selectPagination(pagination));
    }

    /**
     * 功能描述：保存或者修改订单操作历史记录
     *
     * @param request 请求
     * @param dto     订单操作历史记录
     * @return 结果
     */
    @ResponseBody
    @PostMapping("/save")
    public Result<Object> save(HttpServletRequest request, @RequestBody @Validated OrderOperateHistoryDTO dto) throws Exception {
        return Result.saveOrUpdate(orderOperateHistoryService.saveOrUpdate(dto));
    }

    /**
     * 功能描述：根据ID获取订单操作历史记录
     *
     * @param request 请求
     * @param orderOperateHistoryId  订单操作历史记录ID
     * @return 结果
     */
    @ResponseBody
    @PostMapping("/info")
    public Result<OrderOperateHistoryVO> info(HttpServletRequest request, @RequestParam(name = "orderOperateHistoryId") Long orderOperateHistoryId) throws Exception {
        return Result.ok(orderOperateHistoryService.selectById(orderOperateHistoryId));
    }

    /**
     * 功能描述：删除订单操作历史记录
     *
     * @param request 请求
     * @param orderOperateHistoryIds 批量删除的订单操作历史记录ID
     * @return 结果
     */
    @ResponseBody
    @PostMapping("/delete")
    public Result<Object> delete(HttpServletRequest request, @RequestParam(name = "orderOperateHistoryIds") List<Long> orderOperateHistoryIds) {
        return Result.delete(orderOperateHistoryService.delete(orderOperateHistoryIds));
    }

}
